package com.jacobson.huobi.mvp.presenter

import com.jacobson.core.di.annotation.ActivityScope
import com.jacobson.core.mvp.BasePresenter
import com.jacobson.huobi.common.expansion.applySchedulersIoMain
import com.jacobson.huobi.common.expansion.onResponseResult
import com.jacobson.huobi.entities.events.LoginEvent
import com.jacobson.huobi.mvp.contract.EditPasswordContract
import com.jacobson.huobi.mvp.contract.EditSoftwareContract
import com.jacobson.huobi.mvp.contract.KycAuthContract
import com.jacobson.huobi.threads.TokenThread
import com.jacobson.huobi.utils.TokenStorageUtil
import okhttp3.MultipartBody
import org.simple.eventbus.EventBus
import javax.inject.Inject

@ActivityScope
class EditSoftwarePresenter @Inject constructor(
    view: EditSoftwareContract.View,
    model: EditSoftwareContract.Model
) : BasePresenter<EditSoftwareContract.View, EditSoftwareContract.Model>(view, model),
    EditSoftwareContract.Presenter {
    override fun logout() {
        TokenThread.stop()
        TokenStorageUtil.save("")
        EventBus.getDefault().post(LoginEvent(1, null))

        model.logout().applySchedulersIoMain()
            .onResponseResult(view) {resp ->
                view?.onLogoutResultResp(resp)
            }
    }

    override fun logcatUpload(file: MultipartBody.Part, model: String, version: String) {
        this.model.logcatUpload(file, model, version).applySchedulersIoMain()
            .onResponseResult(view) {resp ->
                view?.onLogcatUploadResultResp(resp)
            }
    }

}
